/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

/**
 * 方法一：使用Promise.all
 */
/*(function () {
    let [a, b, c] = ['hello', 'lagou', 'I ♥ U']
    let promiseF = function (str) {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(str)
            }, 10)
        })
    }

    let allPro = [a, b, c].map(item => promiseF(item))

    Promise.all(allPro).then(arr => {
        console.log(arr.join(''));
    })
})()*/

/**
 * 方法二：promise配合async
 */
/*(function () {
    function printHandle(str) {
        return new Promise(resolve => {
            setTimeout(() => {
                // console.log(str);
                resolve(str)
            }, 10)
        })
    }

    async function print() {
        let a = await printHandle('hello')
        let b = await printHandle('lagou')
        let c = await printHandle('I ♥ U')
        console.log(a + b + c);
    }

    print()
})()*/

/**
 * 方法三：Promise的then链式调用
 */
/*(function () {
    function getStr(str) {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(str)
            }, 10)
        })
    }

    getStr('hello').then(_ => {
        return getStr(_ + 'lagou')
    }).then(_ => {
        return getStr(_ + 'I ♥ U')
    }).then(_ => {
        console.log(_);
    })
})()*/
